
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;

using Swaf;
using Swaf.Container;

namespace Articles.Gui.AspNet
{
	[Themeable(true)]
	[ParseChildren(false)]
	public class StandAloneArticleListDisplay : Swaf.Gui.AspNet2.UserControl
	{
		protected List<Control> m_innerChildren = null;
		protected FlexiMap m_macros = new FlexiMap();

		[Category("Appearance")]
		public string PID { get { return (string)m_macros.get("pid"); } set { m_macros.put("pid", value); } }

		[Category("Appearance")]
		public string ParentBizProc { get { return (string)m_macros.get("parentBizProc"); } set { m_macros.put("parentBizProc", value); } }

		[Category("Appearance")]
		public string BoxSkinId { get { return (string)m_macros.get("skinId"); } set { m_macros.put("skinId", value); } }

		[Category("Appearance")]
		public string ListTemplate { get { return (string)m_macros.get("listType"); } set { m_macros.put("listType", value); } }

		[Category("Appearance")]
		public string NavLink { get { return (string)m_macros.get("navLink2"); } set { m_macros.put("navLink2", value); } }

		[Category("Appearance")]
		public string ImageRes { get { return (string)m_macros.get("imageRes"); } set { m_macros.put("imageRes", value); } }

		[Category("Appearance")]
		public string MaxElements { get { return (string)m_macros.get("maxElements"); } set { m_macros.put("maxElements", value); } }

		[Category("Appearance")]
		public string ColumnElements { get { return (string)m_macros.get("colElements"); } set { m_macros.put("colElements", value); } }

		[Category("Appearance")]
		public string DetailLevel { get { return (string)m_macros.get("detailLevel"); } set { m_macros.put("detailLevel", value); } }

        [Category("Appearance")]
        public string IncludeSelf { get { return (string)m_macros.get("includeSelf"); } set { m_macros.put("includeSelf", value); } }

		[Category("Appearance")]
		public string EntireTree { get { return (string)m_macros.get("entireTree"); } set { m_macros.put("entireTree", value); } }

		[Category("Appearance")]
		public string AnimiType { get { return (string)m_macros.get("animiType"); } set { m_macros.put("animiType", value); } }

		[Category("Appearance")]
		public string ListCssClass { get { return (string)m_macros.get("listCssClass"); } set { m_macros.put("listCssClass", value); } }

		[Category("Appearance")]
		public string ChildCssClass { get { return (string)m_macros.get("childCssClass"); } set { m_macros.put("childCssClass", value); } }

		[Category("Appearance")]
		public string ReadMoreText { get { return (string)m_macros.get("readMoreText"); } set { m_macros.put("readMoreText", value); } }
		

        protected override string createCacheKey()
		{
			string key = base.createCacheKey() + WidgetId;
			s_content[key] = null;
			return key;
		}

		protected override System.IO.TextReader Html
		{
			get
			{
				if (NavLink == null)
					NavLink = "$CmpSetting(sitePath)$/articles/$CalcArticleIds($pid$,$uniqueId$)$.aspx";
				if (ParentBizProc == null)
					ParentBizProc = "loginBP";
				if (MaxElements == null)
					MaxElements = "-1";
				if (DetailLevel == null)
					DetailLevel = "basicDetails";
				if (ImageRes == null)
					ImageRes = "Thumbnail";
                if (IncludeSelf == null)
                    IncludeSelf = "True";
                if (EntireTree == null)
                    EntireTree = "True";
				if (ChildCssClass == null)
					ChildCssClass = "articlebox";

				m_macros.put("cssClass", CssClass);
				m_macros.put("id", ID);
				string html = base.Html.ReadToEnd();
				html = Swaf.Application.currentApp.resMgr.resolve(html, m_macros);
				html = html.Replace("$navLink$", ((string)m_macros.get("navLink2")));//.Replace("&","&amp;"));
				return new System.IO.StringReader(html);
			}
		}

		protected override bool createControls()
		{
			if (m_innerChildren == null && Controls.Count > 0)
			{
				m_innerChildren = new List<Control>();
				foreach (Control c in Controls)
					m_innerChildren.Add(c);
			}
			return base.createControls();
		}
		protected override void RenderContents(HtmlTextWriter output)
		{
			Panel mainArea = searchControl("MainArea", this) as Panel;

			if (m_innerChildren != null && mainArea != null)
				foreach (Control c in m_innerChildren)
					mainArea.Controls.Add(c);
			else if (mainArea != null)
				mainArea.Visible = false;

			base.RenderContents(output);
		}
	}
}
